﻿using Cache.Entities;
using Cache.Interfaces;
using Core.AbstractEntities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Stack.Entities;

namespace Test
{
    /// <summary>
    /// Testing the CacheProvider
    /// </summary>
    [TestClass]
    public class UnitTest_CacheProvider
    {
        /// <summary>
        /// Test the file creation and the XML-Well formated with a XSD file
        /// </summary>
        [TestMethod]
        public void TestCache_CacheXmlProvider()
        {
            HpPile hpPile = new HpPile();
            //Initialitation of the elements in the pile
            InitialiseForTesthpile(hpPile);

            HpElement element1 = hpPile.Get(1);
            HpElement element2 = hpPile.Get(2);

            //Add 2 elements in the memory
            hpPile.Memory.AddElement(element1, "var1");
            hpPile.Memory.AddElement(element2, "var2");

            //Initialisation of the ICacheProvider
            ICacheProvider cache = new XMLCacheProvider();
            cache.HpPile = hpPile;
            //Store of the pile
            cache.Store();


            //Restore of the pile
            HpPile pile = cache.Restore();

            Assert.AreEqual("this is a string", pile.Get(1).Value);
            Assert.AreEqual('c', pile.Get(2).Value);
        }
        /// <summary>
        ///Initialitation of the elements in the pile
        /// </summary>
        /// <param name="hpile">Collection</param>
        private static void InitialiseForTesthpile(HpPile hpile)
        {
            HpElement element1 = new HpElement();
            element1.Value = 1;
            HpElement element2 = new HpElement();
            element2.Value = "this is a string";
            HpElement element3 = new HpElement();
            element3.Value = 'c';
            HpElement element4 = new HpElement();
            element4.Value = 3.141516;
            //Add element integer
            hpile.AddElement(element1);
            //Add element string
            hpile.AddElement(element2);
            ////Add element character
            hpile.AddElement(element3);
            ////Add element double
            hpile.AddElement(element4);
        }
    }
}
